package com.standardoperationapp.adapter;



import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;

import com.standardoperationapp.R;
import com.standardoperationapp.bean.CilckEventBean;
import com.standardoperationapp.bean.MyAcessDoorBean;
import com.standardoperationapp.global.GlobalVaries;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

public class ApplyListAdapter extends BaseAdapter {
    private List<MyAcessDoorBean.DataBean> list;
    private LayoutInflater mInflater;
   // private ViewHolder viewHolder;

    public ApplyListAdapter(Context context, List<MyAcessDoorBean.DataBean> list1) {
        list = list1;
        mInflater = LayoutInflater.from(context);
    }



    public int getCount() {
        return list.size();
    }

    public Object getItem(int position) {
        return list.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    public int getItemViewType(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent)
    {
        MyAcessDoorBean.DataBean item = list.get(position);
        ViewHolder viewHolder = null;

        if(convertView == null){
            convertView = mInflater.inflate(R.layout.applykey_list_item, null);
            viewHolder=new ViewHolder(
                    (View) convertView.findViewById(R.id.apply_list_child),
                    (TextView) convertView.findViewById(R.id.apply_txt1),
                    (TextView) convertView.findViewById(R.id.apply_txt2),
                    (TextView) convertView.findViewById(R.id.apply_txt3),
            (TextView) convertView.findViewById(R.id.apply_txt4)

            );
            convertView.setTag(viewHolder);
        }
        else{
            viewHolder = (ViewHolder)convertView.getTag();
        }

        viewHolder.txt1.setText(Integer.toString(position+1));
        viewHolder.txt2.setText(item.getDoorName());
//        viewHolder.txt4.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                Log.e("syj","list  CLICK1 "+Integer.toString(position));
                if(GlobalVaries.idlist.get(position).getState()==1) {
                   // GlobalVaries.idlist.get(position).setState(1);
                   // viewHolder.child.setBackgroundColor(Color.parseColor("#F1F1F1"));
                    viewHolder.txt3.setBackgroundResource(R.drawable.wish_select_on_icon);

                }else{
                  //  GlobalVaries.idlist.get(position).setState(0);
                    viewHolder.txt3.setBackgroundResource(R.drawable.wish_select_off_icon);
                  //  viewHolder.child.setBackgroundColor(Color.WHITE);
                }
//            }
//        });

//        if ((position % 2) == 1) {
//            viewHolder.child.setBackgroundColor(Color.parseColor("#F1F1F1"));
//        } else {
//            viewHolder.child.setBackgroundColor(Color.WHITE);
//        }

//        {
//            viewHolder.child.setBackgroundResource(R.drawable.msgbox_send);
//            viewHolder.msgTextView.setText(item.getComItem());
//        }
//        else
//        {
//            viewHolder.child.setBackgroundResource(R.drawable.msgbox_rec);
//            viewHolder.msgTextView.setText(item.getComItem());
//        }


        return convertView;
    }

    public void upDta(List<MyAcessDoorBean.DataBean> list) {
        this.list = list;
    }

    class ViewHolder
    {
        protected TextView txt1,txt2,txt3,txt4;
        protected View child;


        public ViewHolder(View child, TextView txt1, TextView txt2, TextView txt3, TextView txt4){
            this.child = child;
            this.txt1 = txt1;
            this.txt2 = txt2;
            this.txt3 = txt3;
            this.txt4 = txt4;

        }
    }


}
